package main;

import java.sql.Time;
import java.util.HashMap;

import calcul.MonteCarlo;

import display.myFrame;

public class main {
	
	public static int NORMAL = 0;
	public static int THREADING = 1;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		System.out.println("Begin");
		
		System.out.println(Runtime.getRuntime().availableProcessors());
		
		myFrame frame = new myFrame();
		frame.setVisible(true);	
		
	}
	
	public static HashMap<String, Object> calcul(int cPF, int threadingNB, double stock, double strike, double m, double dR, double cR, double v, int nSte, int nSim)
	{
		HashMap<String, Object> result = new HashMap<String, Object>();
		
		// time begin
		long t1 = System.currentTimeMillis();
		
		
		
		if (threadingNB == main.NORMAL)
		{
			MonteCarlo MC = new MonteCarlo(cPF, stock, strike, m, dR, cR, v, nSte, nSim);
			result.put("value", MC.calcul());
		}
		else
		{
			MonteCarlo MC = new MonteCarlo(cPF, stock, strike, m, dR, cR, v, nSte, nSim);
			result.put("value", MC.calculThread(threadingNB));
		}
		
		// time end
		long t2 = System.currentTimeMillis();
		
		result.put("time", getElapsedTimeHoursMinutesSecondsString(t2 - t1));
		
		return  result;
	}
	
	public static String getElapsedTimeHoursMinutesSecondsString(long elapsedTime) {  
		
	    String format = String.format("%%0%dd", 2);
	    
	    String mil = String.format(format, elapsedTime % 1000);  
	    elapsedTime = elapsedTime / 1000;  
	    
	    String seconds = String.format(format, elapsedTime % 60);  
	    String minutes = String.format(format, (elapsedTime % 3600) / 60);  
	    String hours = String.format(format, elapsedTime / 3600);  
	    String time =  hours + ":" + minutes + ":" + seconds + ":" + mil;  
	    return time;
	}  

}
